package client;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

import client.abilities.CreatureAbility;
import client.equipment.IEquippable;
import java.util.List;

public class Creature implements Serializable {

	private static final long serialVersionUID = 1L;
	private String name;
	private MagicColor color;
	private String creatureType;
	private int experience;
	private int level;
	private int currentHP;
	//private int currentStrength;
	/**Level 1 values */
	private int strength;
	private int maxHP;
	private int accuracy;
	private int speed;
	
	/**Level 100 values */
	private int strengthAt100;
	private int maxHPAt100;
	private int accuracyAt100;
	private int speedAt100;
	
	private int maxEquipment;
	private int criticalChance; // percent chance of critical hit
	private List<CreatureAbility> abilities;
	private List<IEquippable> equipment;
        private List<TimedEffect> effects;
	public Image image;

	private Point location;

	public Creature() {
		location = new Point(250, 250);
		abilities = new ArrayList<CreatureAbility>();
	}

	public void displayStats(Graphics g, int x, int y) {
		g.setFont(GraphicsLoader.getSmallFont());
		g.setColor(Color.BLACK);
		g.drawRect(x, y, 200, 50);
		g.drawString(name, x + 5, y + 15);
		g.drawString(creatureType, x + 65, y + 40);
		g.setColor(color.getColor());
		g.drawString(color.toString(), x + 5, y + 40);
	}

	public void displayQuickStats(Graphics g, int x, int y) {
		g.setFont(GraphicsLoader.getSmallFont());
		g.setColor(Color.BLACK);
		g.drawRect(x, y, 200, 50);
		g.drawString(name, x + 5, y + 15);
		g.drawString("Lvl: " + level, x + 5, y + 40);
		g.drawString(currentHP + " / " + maxHP + "HP", x + 75, y + 40);
	}

	public void displayMoreStats(Graphics g, int x, int y) {
		g.drawRect(x, y, 200, 50);
		g.drawString("Strength: " + strength + "  Speed: " + speed, x + 5,
				y + 15);
		g.drawString("HP: " + maxHP + "   Accuracy: " + accuracy, x + 5, y + 40);
		g.drawString("Starting ability: " + abilities.get(0).getName(), 5, 350);
	}

	public void displayImage(Graphics g, int x, int y) {
		g.setColor(color.getColor());
		g.fillRoundRect(x, y, 40, 40, 5, 5); // until images are loaded
	}

	public void displayOnMap(Graphics g) {
		g.setColor(color.getColor());
		g.fillOval(location.x, location.y, 20, 20);
	}

	private void readObject(java.io.ObjectInputStream in) throws IOException,
			ClassNotFoundException {
		in.defaultReadObject();
	}

	@Override
	public String toString() {
		return "Creature [name=" + name + ", color=" + color
				+ ", creatureType=" + creatureType + ", level=" + level
				+ ", strength=" + strength + ", maxHP=" + maxHP + ", accuracy="
				+ accuracy + ", speed=" + speed + ", maxEquipment="
				+ maxEquipment + ", criticalChance=" + criticalChance + "]";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MagicColor getColor() {
		return color;
	}

	public void setColor(MagicColor color) {
		this.color = color;
	}

	public String getCreatureType() {
		return creatureType;
	}

	public void setCreatureType(String creatureType) {
		this.creatureType = creatureType;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getStrength() {
		int currentStrength = strength;
		for(TimedEffect eff : effects){
			currentStrength += eff.getStrengthBoost();
		}
		for(IEquippable equip : equipment){
			currentStrength += equip.getStrengthBonus();
		}
		return currentStrength;
	}

	public void setStrength(int strength) {
		this.strength = strength;
	}
	/*
	public int getCurrentStrength() {
		return currentStrength;
	}

	public void addCurrentStrength(int currentStrength) {
		this.currentStrength += currentStrength;
	}*/

	public int getMaxHP() {
		return maxHP;
	}

	public void setMaxHP(int maxHP) {
		this.maxHP = maxHP;
	}

	public int getStrengthAt100() {
		return strengthAt100;
	}

	public void setStrengthAt100(int strengthAt100) {
		this.strengthAt100 = strengthAt100;
	}

	public int getMaxHPAt100() {
		return maxHPAt100;
	}

	public void setMaxHPAt100(int maxHPAt100) {
		this.maxHPAt100 = maxHPAt100;
	}

	public int getAccuracyAt100() {
		return accuracyAt100;
	}

	public void setAccuracyAt100(int accuracyAt100) {
		this.accuracyAt100 = accuracyAt100;
	}

	public int getSpeedAt100() {
		return speedAt100;
	}

	public void setSpeedAt100(int speedAt100) {
		this.speedAt100 = speedAt100;
	}

	public int getCurrentHP() {
		return currentHP;
	}

	public void setCurrentHP(int currentHP) {
		this.currentHP = currentHP;
	}
	public void addCurrentHP(int addedHP) {
		this.currentHP += addedHP;
		if(currentHP>maxHP){
			currentHP=maxHP;
		}
	}

	public int getAccuracy() {
		return accuracy;
	}

	public void setAccuracy(int accuracy) {
		this.accuracy = accuracy;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getMaxEquipment() {
		return maxEquipment;
	}

	public void setMaxEquipment(int maxEquipment) {
		this.maxEquipment = maxEquipment;
	}

	public int getCriticalChance() {
		return criticalChance;
	}

	public void setCriticalChance(int criticalChance) {
		this.criticalChance = criticalChance;
	}

	public List<CreatureAbility> getAbilities() {
		return abilities;
	}

	public void addAbility(CreatureAbility ability) {
		this.abilities.add(ability);
	}

	public List<TimedEffect> getEffects() {
		return effects;
	}

	public void addEffect(TimedEffect effect) {
		effects.add(effect);
	}

	public Point getLocation() {
		return location;
	}

	public void setLocation(Point location) {
		this.location = location;
	}
}
